﻿using System;
using System.Windows.Forms;
using System.Collections.Generic;

namespace Rcon
{
	/// <summary>
	/// A Message combines a string message, an int duration, and a string Gametype / Map
	/// </summary>
	public class Message
	{
		private string message = null;
		private int duration = -1;
        private string gametype = null;
        private List<int> visiblePlaylists = new List<int>();
        private string map = null;

        public Message() { }

		public Message(string message, int duration, string gametype, string map)
		{
            if (message == null || duration.Equals(-1) || gametype == null || map == null)
			{
				throw new ArgumentNullException("Message, duration, game type, and map may not be null.");
			}

			this.message = message;
            this.duration = duration;
            this.gametype = gametype;
            this.visiblePlaylists = new GametypeLookup().GetAllowablePlaylists(gametype);
            this.map = map;
		}

		public string GetMessage
		{
            get { return message; }
		}

		public int GetDuration
		{
            get { return duration; }
		}

        public string GetGametype
        {
            get { return gametype; }
        }

        public List<int> GetVisiblePlayList
        {
            get { return visiblePlaylists; }
        }

        public string GetMap
        {
            get { return map; }
        }

        public DataGridViewRow ToRow(DataGridViewRow row)
        {
            row.Cells[0].Value = message;
            row.Cells[1].Value = duration;
            row.Cells[2].Value = gametype;
            row.Cells[3].Value = map;
            return row;
        }

        public Message FromRow(DataGridViewRow row)
        {
            return new Message(row.Cells[0].Value.ToString(), Convert.ToInt16(row.Cells[1].Value), row.Cells[2].Value.ToString(), row.Cells[3].Value.ToString());
        }

		public override string ToString()
		{
			return message + ";" + duration.ToString() + ";" + gametype + ";" + map;
		}
	}
}
